cmake_minimum_required(VERSION 3.6)

SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

project(TestServer)

set(CMAKE_CXX_STANDARD 14)

set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE PATH "Installation directory" FORCE)
message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}")
#SET(CMAKE_C_FLAGS  "${CMAKE_C_FLAGS}  -O3 -Wall")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}  -O3 -Wall")
set(GEEJOAN_OUTPUTDIR ${CMAKE_SOURCE_DIR}/${CMAKE_SYSTEM_NAME}.out)
if (MSVC)

    set(TARGETS_LIST
            GeeJoan_Client
            )

    set(CLIENT_LINK_LIST
            GeeJoanProtocol
            WS2_32
            winmm
            wldap32
            )

elseif (UNIX)

    add_subdirectory(libs/handy)
    set(TARGETS_LIST
            GeeJoan_SingleServer
            GeeJoan_Client
            GeeJoan_Client_CMD
            libprotobuf
            )


    set(CLIENT_LINK_LIST
            GeeJoanProtocol
            )

endif ()

add_subdirectory(libs/SQLiteCpp)
add_subdirectory(libs/protobuf/cmake)
include_directories(includes)
include_directories(src)
add_subdirectory(src)

add_subdirectory(tests)

# 服务端测试
add_executable(GeeJoan_SingleServer Server.cpp)
target_link_libraries(GeeJoan_SingleServer ServerGeeJoan)

add_executable(GeeJoan_Client Client.cpp src/Tools/CommonTool.cpp src/Tools/sockcompat.c)
#
target_link_libraries(GeeJoan_Client GeeJoanProtocol)

add_executable(GeeJoan_Client_CMD cmdClient.cpp src/Tools/CommonTool.cpp src/Tools/ParsingArgs.cpp)
#
target_link_libraries(GeeJoan_Client_CMD GeeJoanProtocol)

INSTALL(TARGETS
        ${TARGETS_LIST}

        EXPORT GeeJoan-targets
        RUNTIME DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoan/bin
        LIBRARY DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoan/libs
        ARCHIVE DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoan/libs)

INSTALL(FILES
        ${CMAKE_SOURCE_DIR}/src/GeeJoan/AuthModule.pb.h
        ${CMAKE_SOURCE_DIR}/src/GeeJoan/ErrorModule.pb.h
        ${CMAKE_SOURCE_DIR}/src/GeeJoan/IoTModule.pb.h
        ${CMAKE_SOURCE_DIR}/src/GeeJoan/NetWorkPackage.pb.h
        DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoan/include/GeeJoan)

INSTALL(FILES
        ${CMAKE_SOURCE_DIR}/src/Business/internaltypes.h
        DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoan/include/Business)

INSTALL(FILES
        ${CMAKE_SOURCE_DIR}/src/Tools/CommonTool.h
        ${CMAKE_SOURCE_DIR}/src/Tools/CommonTool.cpp
        ${CMAKE_SOURCE_DIR}/src/Tools/sockcompat.c
        ${CMAKE_SOURCE_DIR}/src/Tools/sockcompat.h
        ${CMAKE_SOURCE_DIR}/src/Tools/ParsingArgs.cpp
        ${CMAKE_SOURCE_DIR}/src/Tools/ParsingArgs.h
        DESTINATION ${GEEJOAN_OUTPUTDIR}/DemoClient/Tools)

INSTALL(FILES
        ${CMAKE_SOURCE_DIR}/tests/Demo/Client.cpp
        ${CMAKE_SOURCE_DIR}/tests/Demo/CMakeLists.txt
        ${CMAKE_SOURCE_DIR}/tests/Demo/buildLinux.sh
        DESTINATION ${GEEJOAN_OUTPUTDIR}/DemoClient)

INSTALL(FILES
        ${CMAKE_SOURCE_DIR}/tests/Demo/runServer.sh
        ${CMAKE_SOURCE_DIR}/tests/Demo/libstdc++.so.6
        DESTINATION ${GEEJOAN_OUTPUTDIR}/GeeJoan/bin
        )
